<template>
  <div class="container">
    <el-container class="container-box">
      <!-- 左侧 -->
      <el-aside class="left-aside" width="260px">
        <div class="logo-box">
          <img class="logo" src="../assets/logo.png" />
          <h2
            style="
              color: #409eff;
              font-size: 18px;
              font-weight: normal;
              margin-top: 5px;
            "
          >
            {{ title }}
          </h2>
        </div>
        <img style="height: 240px" src="../assets/login/aside.svg" alt="" />
      </el-aside>
      <!-- 内容 -->
      <el-main class="main">
        <el-tabs v-model="activeName">
          <el-tab-pane label="账号登录" name="pwdLogin">
            <el-form class="login-info-form">
              <!-- 用户名输入框 -->
              <el-form-item style="margin-top: 12px">
                <el-input
                  placeholder="请输入用户名(支持手机号码、员工号、邮箱)"
                  v-model="form.username"
                >
                  <template slot="prepend"
                    ><i class="el-icon-user"></i
                  ></template>
                </el-input>
              </el-form-item>
              <el-form-item>
                <!-- 密码输入框 -->
                <el-input
                  placeholder="请输入登录密码"
                  show-password
                  v-model="form.password"
                >
                  <template slot="prepend"
                    ><i class="el-icon-unlock"></i
                  ></template>
                </el-input>
              </el-form-item>
              <el-form-item>
                <div style="display: flex; justify-content: space-between">
                  <el-checkbox v-model="form.rememberMe"
                    >记住登录状态</el-checkbox
                  >
                  <el-button type="text">忘记密码?</el-button>
                </div>
              </el-form-item>
              <el-form-item>
                <el-button
                  @click="loginSend"
                  style="width: 100%; height: 44px"
                  type="primary"
                  >登录</el-button
                >
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="扫码登录" name="codeLogin"
            >未开发，敬请期待...</el-tab-pane
          >
        </el-tabs>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import { isEmpty } from "@/utils/stringUtils";

export default {
  name: "Login",
  data() {
    return {
      activeName: "pwdLogin",
      title: "",
      form: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    // 校验登录
    verifyLogin() {
      if (isEmpty(this.form.username)) {
        this.$modal.msgError("用户名不能为空!");
        return false;
      }
      if (isEmpty(this.form.password)) {
        this.$modal.msgError("用户密码不能为空!");
        return false;
      }
      return true;
    },
    // 登录
    loginSend() {
      // 校验登录
      const verifyResult = this.verifyLogin();
      if (verifyResult) {
        this.$store.dispatch("Login", this.form).then((res) => {
          if (res.code == 200) {
            this.$modal.msgSuccess("登录成功!");
            this.$router.push("/home");
          } else {
            this.$message.error(res.msg);
          }
        });
      }
    },
  },
  created() {
    this.title = process.env.VUE_APP_SYSTEM_NAME;
  },
};
</script>

<style scoped lang="scss">
::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
}

.container {
  height: 100vh;
  background: url("../assets/login/bg.jpg") no-repeat;
  background-size: 100% 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container-box {
  max-width: 720px;
  height: 360px;

  .logo-box {
    display: flex;
    align-items: center;
    flex-direction: column;
    margin-top: 30px;

    .logo {
      width: 50px;
    }
  }
}

.left-aside {
  display: flex;
  flex-direction: column;
  background-color: #ebf4fe;
}

.main {
  background-color: #ffffff;
}

::v-deep .login-info-form {
  .el-input-group__prepend,
  .el-input__inner:focus,
  .el-input__inner {
    border: 1px solid rgba(235, 238, 245, 0.8);
  }

  .el-input-group__prepend {
    background-color: #ffffff !important;
    border-right: none;
    width: 40px;
    font-size: 20px;
  }

  .el-input__inner {
    height: 44px;
    padding-left: 0;
    border-left: none !important;
  }
}
</style>